<template>
  <view :style="themeColor">
    <view class="page">
      <view class="flex benben-position-layout flex flex-wrap align-center yonghurenzheng_flex_0"
        :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
        <view class='flex flex-wrap align-center justify-between flex-sub yonghurenzheng_fd0_0'>
          <view class='flex flex-wrap align-center yonghurenzheng_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="back"
            data-url="1">
            <text class='fu-iconfont2  yonghurenzheng_fd0_0_c0_c0'>&#xE794;</text>
          </view>
          <view class='flex flex-wrap align-stretch justify-center'>
            <text class='yonghurenzheng_fd0_0_c1_c0'>用户认证</text>
          </view>
          <view class='flex flex-wrap align-center justify-end yonghurenzheng_fd0_0_c0'>
          </view>
        </view>

      </view>
      <view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
      <!---flex布局flex布局开始-->
      <view class="flex benben-flex-layout flex-wrap align-center">
        <view class='flex flex-wrap align-center justify-center yonghurenzheng_fd1_0'>

          <text v-if="check_status==='0'">审核中</text>
          <text v-if="check_status==='2'">审核失败</text>
          <text v-if="check_status==='1'">已认证</text>
          <text v-if="check_status==='' || check_status==='-1'">请填写真实的信息，我们将会保证您的信息安全</text>
        </view>
      </view>

      <!---flex布局flex布局结束-->

      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout">
        <view class='flex flex-direction flex-wrap align-stretch yonghurenzheng_fd2_0'>
          <view class='flex flex-wrap align-center justify-between yonghurenzheng_fd2_0_c0'>
            <text class='yonghurenzheng_fd2_0_c0_c0'>用户类型</text>
            <benben-select-diy ref="showSelectPopup1708237743455" class-name='flex flex' default-type="value"
              :items.sync="userType" v-model="type" default-label="name" :allow-cancel='false' type="radio"
              :disabled='false'>
              <template v-for='(item,key0) in userType'>
                <view v-if="item.isSelected" class='flex align-center justify-center flex yonghurenzheng_fd2_0_c0_c1_c0'
                  :key="" @tap="$refs.showSelectPopup1708237743455.tapHandle(key0)">
                  <image class='yonghurenzheng_fd2_0_c0_c1_c0_c0' mode="aspectFill" :src='STATIC_URL+"3.png"'></image>
                  <text class='yonghurenzheng_fd2_0_c0_c1_c0_c1'>{{item.name}}</text>
                </view>
                <view v-else class='flex align-center flex' style=" margin: 0rpx 32rpx 0rpx 0rpx; " :key=""
                  @tap="$refs.showSelectPopup1708237743455.tapHandle(key0)">
                  <image class='yonghurenzheng_fd2_0_c0_c1_c1_c0' mode="aspectFit" :src='STATIC_URL+"11.png"'></image>
                  <text class='yonghurenzheng_fd2_0_c0_c1_c0_c1'>{{item.name}}</text>
                </view>
              </template>
            </benben-select-diy>
          </view>
          <view class='flex flex-wrap align-center yonghurenzheng_fd2_0_c0'>
            <text class='yonghurenzheng_fd2_0_c0_c0'>姓名</text>
            <benben-input class='flex-sub yonghurenzheng_fd2_0_c1_c1' type="text" :placeholder="`请输入`"
              confirm-type="done" :maxlength="10" v-model="true_name"
              placeholder-style="color:rgba(51, 51, 51, 1);font-size:32rpx" />
          </view>
          <view class='flex flex-wrap align-center yonghurenzheng_fd2_0_c0'>
            <text class='yonghurenzheng_fd2_0_c0_c0'>手机号</text>
            <benben-input class='flex-sub yonghurenzheng_fd2_0_c1_c1' type="tel" :placeholder="`请输入`"
              confirm-type="done" :maxlength="11" placeholder-style="color:rgba(51, 51, 51, 1);font-size:32rpx"
              v-model="mobile" />
          </view>
          <view class='flex flex-wrap align-center yonghurenzheng_fd2_0_c0'>
            <text class='yonghurenzheng_fd2_0_c0_c0'>身份证号</text>
            <benben-input class='flex-sub yonghurenzheng_fd2_0_c1_c1' type="tel" :placeholder="`请输入`"
              confirm-type="done" :maxlength="20" placeholder-style="color:rgba(51, 51, 51, 1);font-size:32rpx"
              v-model="idcard_no" />
          </view>
          <view class='flex flex-wrap align-center yonghurenzheng_fd2_0_c3'>
            <text class='yonghurenzheng_fd2_0_c0_c0'>请上传资料</text>
          </view>
          <view class='flex flex-wrap align-center justify-around'>
            <view class='flex flex-direction flex-wrap align-center self-center justify-center'>
              <view class="upload position-relative">
                <text v-if="head_img != ''" @tap="head_img = ''"
                  class='fu-iconfont2 position-absolute yonghurenzheng_fd2_0_c4_c0_c0_icon'>&#xE8E7;</text>
                <image class=" yonghurenzheng_fd2_0_c4_c0_c0_image" mode="aspectFit"
                  @tap="soloChooseImage('head_img','head_img',false,false)"
                  :src="head_img ? head_img : STATIC_URL+'48.png'"></image>
              </view>
              <text class='yonghurenzheng_fd2_0_c4_c0_c1'>门店照片</text>
            </view>
            <view class='flex flex-direction flex-wrap align-center self-center justify-center'>
              <view class="upload position-relative">
                <text v-if="img != ''" @tap="img = ''"
                  class='fu-iconfont2 position-absolute yonghurenzheng_fd2_0_c4_c0_c0_icon'>&#xE8E7;</text>
                <image class=" yonghurenzheng_fd2_0_c4_c0_c0_image" mode="aspectFit"
                  @tap="soloChooseImage('img','img',false,false)" :src="img ? img : STATIC_URL+'48.png'"></image>
              </view>
              <text class='yonghurenzheng_fd2_0_c4_c0_c1'>营业执照</text>
            </view>
            <view class='flex flex-direction flex-wrap align-center self-center justify-center'>
              <view class="upload position-relative">
                <text v-if="img_book != ''" @tap="img_book = ''"
                  class='fu-iconfont2 position-absolute yonghurenzheng_fd2_0_c4_c0_c0_icon'>&#xE8E7;</text>
                <image class=" yonghurenzheng_fd2_0_c4_c0_c0_image" mode="aspectFit"
                  @tap="soloChooseImage('img_book','img_book',false,false)"
                  :src="img_book ? img_book : STATIC_URL+'48.png'">
                </image>
              </view>
              <text class='yonghurenzheng_fd2_0_c4_c0_c1'>授权书</text>
            </view>
          </view>
          <view class='flex flex-wrap align-center yonghurenzheng_fd2_0_c3'>
            <text class='yonghurenzheng_fd2_0_c0_c0'>请上传个人资料</text>
          </view>
          <view class='flex flex-wrap align-center justify-around'>
            <view class='flex flex-direction flex-wrap align-center self-center justify-center'>
              <view class="upload position-relative">
                <text v-if="idcard_portrait != ''" @tap="idcard_portrait = ''"
                  class='fu-iconfont2 position-absolute yonghurenzheng_fd2_0_c4_c0_c0_icon'>&#xE8E7;</text>
                <image class=" yonghurenzheng_fd2_0_c4_c0_c0_image" mode="aspectFit"
                  @tap="soloChooseImage('idcard_portrait','idcard_portrait',false,false)"
                  :src="idcard_portrait ? idcard_portrait : STATIC_URL+'48.png'"></image>
              </view>
              <text class='yonghurenzheng_fd2_0_c4_c0_c1'>身份证正面</text>
            </view>
            <view class='flex flex-direction flex-wrap align-center self-center justify-center'>
              <view class="upload position-relative">
                <text v-if="idcard_emblem != ''" @tap="idcard_emblem = ''"
                  class='fu-iconfont2 position-absolute yonghurenzheng_fd2_0_c4_c0_c0_icon'>&#xE8E7;</text>
                <image class=" yonghurenzheng_fd2_0_c4_c0_c0_image" mode="aspectFit"
                  @tap="soloChooseImage('idcard_emblem','idcard_emblem',false,false)"
                  :src="idcard_emblem ? idcard_emblem : STATIC_URL+'48.png'"></image>
              </view>
              <text class='yonghurenzheng_fd2_0_c4_c0_c1'>身份证反面</text>
            </view>
          </view>
          <button class='yonghurenzheng_fd2_0_c5' @click.stop="submit">提交</button>
        </view>
      </view>




    </view>
  </view>
</template>
<script>
  import UploadImage from '@/common/utils/upload-image.js'
  import {
    validate
  } from '@/common/utils/validate.js'

  export default {
    components: {},

    data() {
      return {
        "userType": [{
          "name": "普通用户",
          "value": "1",
          "image": ""
        }, {
          "name": "商户/企业",
          "value": "2",
          "image": ""
        }],
        true_name: '',
        head_img: '', //	门头照片
        img: '', //营业执照
        img_book: '', //授权书
        idcard_emblem: '',
        idcard_portrait: '',
        idcard_no: '',
        mobile: '',
        type: '1',
        check_status: ''
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },
      userInfo: {
        get() {
          return this.$store.state.userInfo
        },
        set() {
          this.$store.commit('updateUserInfo', value)
        },
      }
    },
    watch: {},
    onLoad(options) {
      let {
        grass_type
      } = options
      if (grass_type !== undefined) this.grass_type = grass_type
      this.getData()
      console.log('this.userInfo', this.userInfo)
    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {},
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      getData() {
        this.$api.post(global.apiUrls.post65d1bfe2c7317).then(res => {
          if (res.data.code == 1) {
            this.check_status = res.data.data.check_status
            if (res.data.data.type != '-1') {

              this.true_name = res.data.data.true_name
              this.type = res.data.data.type
              this.head_img = res.data.data.head_img
              this.img = res.data.data.img
              this.img_book = res.data.data.img_book
              this.mobile = res.data.data.mobile
              this.idcard_no = res.data.data.idcard_no
              this.idcard_portrait = res.data.data.idcard_portrait
              this.idcard_emblem = res.data.data.idcard_emblem
            }

          }
        })
      },
      submit() {
        if (!this.true_name) {
          this.$message.info('请输入真实姓名')
          return;
        }
        if (!this.mobile) {
          this.$message.info('请输入联系方式')
          return;
        }
        if (!this.idcard_no) {
          this.$message.info('请输入身份证号')
          return;
        }
        if (!validate(this.mobile, 'phone')) {
          this.$message.info('请输入正确的手机号');
          return false;
        }
        if (!this.head_img) {
          this.$message.info('请选择门店照片')
          return;
        }
        if (!this.img) {
          this.$message.info('请选择营业执照')
          return;
        }
        if (!this.img_book) {
          this.$message.info('请选择授权书')
          return;
        }
        if (!this.idcard_emblem) {
          this.$message.info('请选择身份证反面')
          return;
        }
        if (!this.idcard_portrait) {
          this.$message.info('请选择身份证正面')
          return;
        }
        this.$api.post(global.apiUrls.post65d1bddab7ce3, {
          true_name: this.true_name,
          head_img: this.head_img,
          img: this.img,
          img_book: this.img_book,
          mobile: this.mobile,
          type: this.type,
          user_id: this.userInfo.userinfo.id,
          idcard_emblem: this.idcard_emblem,
          idcard_portrait: this.idcard_portrait,
          idcard_no: this.idcard_no
        }).then(res => {
          if (res.data.code == 1) {
            // uni.navigateBack()
            uni.switchTab({
              url: `/pages/tabBar/orderList/orderList`
            })
          } else {
            this.$message.info(res.data.msg)
          }
        })
      },
      //上传单图、多图方法
      soloChooseImage(id, path, obj, obj1, fnName = false) {
        let self = this
        if (!obj) obj = this
        if (!obj1) obj1 = this
        if (self.uploading) {
          return
        }
        // 从相册中选择图片
        uni.chooseImage({
          count: 1, // 默认3
          sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
          success: function(res) {
            self.uploading = true
            // 开始上传
            new UploadImage(res.tempFiles, {
              complete: function(res) {
                self.uploading = false
                if (id) self.$set(obj, id, res[0].id)
                if (path) self.$set(obj1, path, res[0].path)
                if (fnName) self[fnName]()
              },
            })
          },
        })
      },
    }
  };
</script>
<style lang="scss" scoped>
  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: rgba(255, 255, 255, 1);
    background-size: 100% auto;
  }

  .yonghurenzheng_flex_0 {
    border-bottom: 1px solid #eee;
    background: #fff;
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
    background-size: 100% auto !important;
  }

  .yonghurenzheng_fd0_0_c1_c0 {
    font-size: 36rpx;
    font-weight: 700;
    color: #333333;
    line-height: 50rpx;
  }

  .yonghurenzheng_fd0_0_c0_c0 {
    font-size: 36rpx;
    color: #333;
  }

  .yonghurenzheng_fd0_0_c0 {
    width: 120rpx;
  }

  .yonghurenzheng_fd0_0 {
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .yonghurenzheng_fd1_0 {
    background: #FFECE3;
    width: 750rpx;
    height: 80rpx;
    color: rgba(217, 50, 32, 1);
    text-align: center;
  }

  .yonghurenzheng_fd2_0_c5 {
    background: #10337E;
    border-radius: 44rpx 44rpx 44rpx 44rpx;
    width: 686rpx;
    // line-height: 60rpx;
    font-size: 32rpx;
    color: #fff;
    height: 88rpx;
    margin: 100rpx 0rpx 0rpx 0rpx;
  }

  .yonghurenzheng_fd2_0_c4_c0_c1 {
    line-height: 50rpx;
  }

  .yonghurenzheng_fd2_0_c4_c0_c0_image {
    width: 210rpx;
    height: 210rpx;
  }

  .yonghurenzheng_fd2_0_c4_c0_c0_icon {
    top: 0rpx;
    right: 0rpx;
    z-index: 10;
    color: #ff5536;
  }

  .yonghurenzheng_fd2_0_c3 {
    padding: 32rpx 0rpx 32rpx 0rpx;
  }

  .yonghurenzheng_fd2_0_c1_c1 {
    text-align: right;
    color: #333333;
    font-size: 32rpx;
    font-weight: 500;
    line-height: 48rpx;
  }

  .yonghurenzheng_fd2_0_c0_c1_c1_c0 {
    width: 36rpx;
    height: 36rpx;
    margin: 0rpx 012rpx 0rpx 0rpx;
  }

  .yonghurenzheng_fd2_0_c0_c1_c0_c1 {
    font-size: 32rpx;
  }

  .yonghurenzheng_fd2_0_c0_c1_c0_c0 {
    width: 36rpx;
    height: 36rpx;
    margin: 0rpx 12rpx 0rpx 0rpx;
  }

  .yonghurenzheng_fd2_0_c0_c1_c0 {
    margin: 0rpx 32rpx 0rpx 0rpx;
  }

  .yonghurenzheng_fd2_0_c0_c0 {
    color: #4B5269;
    font-size: 32rpx;
    font-weight: 500;
    line-height: 48rpx;
  }

  .yonghurenzheng_fd2_0_c0 {
    border-bottom: 1px solid #eee;
    padding: 32rpx 0rpx 32rpx 0rpx;
  }

  .yonghurenzheng_fd2_0 {
    padding: 0rpx 32rpx 0rpx 32rpx;
  }
</style>
